package com.fiberhome.app.network;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created by Deed on 2018/1/16.
 */

public abstract class CallBack<T extends IData> {

    private Class<T> entityClass;

    /**
     *
     */
    public CallBack() {
        init();
    }

    private void init() {
        try {
            Type genType = getClass().getGenericSuperclass();
            Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
            entityClass = (Class<T>) params[0];
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     *
     * @return Class<T>
     */
    public final Class<T> getEntityClass() {
        if (entityClass == null) {
            init();
        }
        return entityClass;
    }

    /**
     *
     * @param t T
     */
    public  abstract void onSuccess(T t);

    /**
     *
     * @param failure Failure
     */
    public  abstract void onFailure(Failure failure);
}
